package com.xy.server.database;

import java.net.URL;
import java.sql.*;

public class SqliteDBService {

    private static final String Class_Name = "org.sqlite.JDBC";

    protected static Connection connection = null;

    public static void main(String args[]) {
        // load the sqlite-JDBC driver using the current class loader

        Connection connection = null;
        try {
            connection = createConnection("/Users/agan/IdeaProjects/XYProject/db.sqlite");
            //func1(connection);
            System.out.println("Success!");
        }  catch (SQLException e) {
            System.err.println(e.getMessage());
        } catch(Exception e) {
            e.printStackTrace();
        } finally{
            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (SQLException e) {
                // connection close failed.
                System.err.println(e);
            }
        }
    }


    // 创建Sqlite数据库连接
    public static Connection createConnection(String dbPath) throws SQLException, ClassNotFoundException{
        String DB_URL = "jdbc:sqlite:" + dbPath;
            Class.forName(Class_Name);
            connection = DriverManager.getConnection(DB_URL);
        return connection;
    }

    public static void closeConnection() throws SQLException, ClassNotFoundException{
        if (connection != null) {
            connection.close();
        }
    }


}
